package com.wx.myatomikos.service;


import com.wx.myatomikos.dao.UserInfoDao;
import com.wx.myatomikos.dao2.UserInfoDao2;
import com.wx.myatomikos.entity.UserInfo;
import com.wx.myatomikos.entity2.UserInfo2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @ClassName UserInfoService
 * @Author wx
 * @Description 用户信息业务层
 * @Date 2018-12-27-21:44
 */
@Service
public class UserInfoService {
    @Autowired
    private UserInfoDao userInfoDao;

    @Autowired
    private UserInfoDao2 userInfoDao2;

    public void save(UserInfo userInfo){
        userInfoDao.addUserInfo(userInfo);
    }


    @Transactional(value = "transactionManager")
    public void  testAtomikos(){
        UserInfo userInfo = new UserInfo();
        userInfo.setName("wx_mybatis_db_1_err");
        userInfo.setJobNumber("wx_mybatis_db_1_0001_err");
        userInfo.setCreateTime(new Date());
        userInfoDao.addUserInfo(userInfo);
        if (userInfo != null){
            throw new RuntimeException("抛出异常测试是否回滚");
        }
        UserInfo2 userInfo2 = new UserInfo2();
        userInfo2.setName("wx_mybatis_db_2_err");
        userInfo2.setJobNumber("wx_mybatis_db_2_0001_err");
        userInfo2.setCreateTime(new Date());
        userInfoDao2.addUserInfo(userInfo2);
    }

}
